package com.example.uit_management;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ArrayAdapterTestSchedule extends BaseAdapter {
	// XML node keys
    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;   
    
    public ArrayAdapterTestSchedule(Activity a, ArrayList<HashMap<String, String>> d) {    	
        activity = a;        
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }   
    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.testschedule_row, null);

        // Get id of row
        TextView Ma = (TextView)vi.findViewById(R.id.Ma_TextView_testschedule); 
        TextView Ten = (TextView)vi.findViewById(R.id.Ten_TextView_testschedule);        
        TextView Lop = (TextView)vi.findViewById(R.id.Lop_TextView_testschedule);  
        TextView Loai = (TextView) vi.findViewById(R.id.Loai_TextView_testschedule);
        TextView Ca = (TextView) vi.findViewById(R.id.Ca_TextView_testschedule);
        TextView Ngay = (TextView) vi.findViewById(R.id.Ngay_TextView_testschedule);
        TextView Phong = (TextView) vi.findViewById(R.id.Phong_TextView_testschedule);
        TextView SiSo = (TextView) vi.findViewById(R.id.SiSo_TextView_testschedule);
        TextView NienKhoa = (TextView) vi.findViewById(R.id.NienKhoa_Testschedule);

        HashMap<String, String> array = new HashMap<String, String>();
        array = data.get(position);
        String a= "Bao cao :"+ position;
        // Setting all values in listview
        
        //-- Set Ma mon
        Ma.setText(array.get(JsonParser_schedule.KEY_courseID));
        Ma.setBackgroundResource(R.drawable.blue_bar8);
        //Subname_score.setPaintFlags(Subname_score.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
        
        //-- Ten Mon
        Ten.setText(array.get(JsonParser_schedule.KEY_subjectName));      
        Ten.setBackgroundResource(R.drawable.blue_bar8);  
        
        //-- Lop thi..............
        Lop.setText(array.get(JsonParser_schedule.KEY_scheduleID));      
        Lop.setBackgroundResource(R.drawable.blue_bar8);  
        
        //-- loai mon thu hanh hay ly thuyet
        Loai.setText(array.get(JsonParser_schedule.KEY_courseType));      
        Loai.setBackgroundResource(R.drawable.blue_bar8);          
    
      //-- ca thi
        Ca.setText(array.get(JsonParser_schedule.KEY_scheduleTime));      
        Ca.setBackgroundResource(R.drawable.blue_bar8);  
      //-- Ngay thi
        Ngay.setText(array.get(JsonParser_schedule.KEY_scheduleDay));      
        Ngay.setBackgroundResource(R.drawable.blue_bar8);  
      //-- Phong thi
        Phong.setText(array.get(JsonParser_schedule.KEY_roomID));      
        Phong.setBackgroundResource(R.drawable.blue_bar8);  
        //-- si so lop thi
        SiSo.setText(array.get(JsonParser_schedule.KEY_scheduleSize));      
        SiSo.setBackgroundResource(R.drawable.blue_bar8);
           
        //-- set hoc ki
        NienKhoa.setText("Nien Khoa");
        NienKhoa.setVisibility(View.GONE);
		NienKhoa.setHeight(0);
		NienKhoa.setBackgroundResource(0);
		
//		////////////////////////
//		// hien hoc ki hoc
//		//////////////////////
//		// Ap dung cho 1 hoac tat ca hoc ki
//        if(Activity_list_testschedule.getSemester_Spinner().toString().equals("Tất cả")|| true){ 
//        	Log.e(ArrayAdapterScore.class.toString(), "dung 1");
//        	if(position !=0){
//        		Log.e(ArrayAdapterScore.class.toString(), "dung 2");
//        		if(!(data.get(position-1).get(JsonParser_regCourse.KEY_semesterYear).equals(data.get(position).get(JsonParser_regCourse.KEY_semesterYear)))){
//        	/*		Subname_score.setBackgroundResource(R.drawable.border_textview_score_red);
//        		    classID_core.setBackgroundResource(R.drawable.border_textview_score_red);
//        		    scorefinal.setBackgroundResource(R.drawable.border_textview_score_red);*/
//        		// thay doi nien khoa
//        			Log.e(ArrayAdapterScore.class.toString(), "dung 3.1");
//        			// set visible
//        			Semester.setVisibility(View.VISIBLE);        			
//        			// set text
//        			Semester.setText(data.get(position).get(JsonParser_regCourse.KEY_semesterYear)+"_Học Kỳ :"+data.get(position).get(JsonParser_regCourse.KEY_semesterIndex));
//        			//set height        
//        			//Semester.setHeight(Activity_Score.Height_sore);
//        	        Subname_score.setPaintFlags(Subname_score.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
//        			// set backgroud
//        			Semester.setBackgroundResource(R.drawable.blue_bar7);
//
//        		}else if(!(data.get(position-1).get(JsonParser_regCourse.KEY_semesterIndex).equals(data.get(position).get(JsonParser_regCourse.KEY_semesterIndex)))){
//        			/*Subname_score.setBackgroundResource(R.drawable.border_textview_score_red);
//        		    classID_core.setBackgroundResource(R.drawable.border_textview_score_red);
//        		    scorefinal.setBackgroundResource(R.drawable.border_textview_score_red);*/
//        			// thay doi nien khoa
//        			Log.e(ArrayAdapterScore.class.toString(), "dung 3.2");
//        			// set visible
//        			Semester.setVisibility(View.VISIBLE);        			
//        			// set text
//        			Semester.setText(data.get(position).get(JsonParser_regCourse.KEY_semesterYear)+"_Học Kỳ :"+data.get(position).get(JsonParser_regCourse.KEY_semesterIndex));
//        			//set height
//        			Semester.setHeight(Activity_Score.Height_sore);
//        			// set backgroud
//        			Semester.setBackgroundResource(R.drawable.blue_bar7);
//        		}        		
//        	}        	
//        	else{
//        		// thay doi nien khoa
//    			Log.e(ArrayAdapterSchedule.class.toString(), "dung 3.3: "+Activity_Score.Height_sore);
//    			// set visible
//    			Semester.setVisibility(View.VISIBLE);        			
//    			// set text
//    			Semester.setText(data.get(position).get(JsonParser_regCourse.KEY_semesterYear)+"_Học Kỳ :"+data.get(position).get(JsonParser_regCourse.KEY_semesterIndex));
//    			//set height        
//    			Semester.setHeight(Activity_Score.Height_sore);
//    			// set backgroud
//    			Semester.setBackgroundResource(R.drawable.blue_bar7);
//        	}        	
//        	// check diem duoi trung binh hoac ko co diem
//            Check_Score_Fail(array, data, position);
//        } 
        return vi;        
    }
	//////////////////////////////
	//danh dau mon hoc da hoc lai
	///////////////////////////////
    /**danh dau mon hoc da hoc lai, hoac rot */
//    void Check_Score_Fail(HashMap<String, String> array , ArrayList<HashMap<String,String>> data, int position){
//
//		Log.e(ArrayAdapterScore.class.toString(), "4");
//		// vong lap
//		for (int i = 0; i < data.size(); i++) {
//		Log.e(ArrayAdapterScore.class.toString(), "4.1");
//		//mon rot hoac chua co diem
//		if(!array.get(JsonParser_regCourse.KEY_scoreFinal).equals("")){			
//			if((Float.parseFloat(array.get(JsonParser_regCourse.KEY_scoreFinal).toString()))<=5){
//				//Subname_score.setHighlightColor(color.black);
//		        Subname_score.setPaintFlags(Subname_score.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
//		} 
//		}else{
//		// rot hoac chua co diem
//			Log.e(ArrayAdapterScore.class.toString(),"Black");
//        	Subname_score.setPaintFlags(Subname_score.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
//		}
//		if(i!=position){
//		Log.e(ArrayAdapterScore.class.toString(), "dung 6"+i);
//		if(data.get(i).get(JsonParser_regCourse.KEY_subjectID).equals(array.get(JsonParser_regCourse.KEY_subjectID))){
//			Subname_score.setTypeface(null,Typeface.BOLD);
//			classID_core.setTypeface(null,Typeface.BOLD);
//			scorefinal.setTypeface(null,Typeface.BOLD);
//			subjectCredit.setTypeface(null,Typeface.BOLD);        			   
//			break;
//		}else
//			Subname_score.setTypeface(null,Typeface.NORMAL);
//			classID_core.setTypeface(null,Typeface.NORMAL);
//			scorefinal.setTypeface(null,Typeface.NORMAL);
//			subjectCredit.setTypeface(null,Typeface.NORMAL); 
//		}
//		Log.e(ArrayAdapterScore.class.toString(), "dung 7"+i);
//		}	
//    }
}